<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<div class="mainBody" style="overflow: auto;width:680px">
    <div class="editBody">
       <?php echo form_open_multipart('app/edit_app_param/'.$app['app_id'].'/'.$cur_chcode); ?>
       <input type="hidden" name='os' value='<?php echo $cur_os;?>' />
        <div class="bodyTitle" style="">
            <div class="titleIcon editTitle"></div>
            <p class="titleName fontDinproMedium" style="">Pack</p>
        </div>
        <div class="bodyDiv fontDinpro">
        	<div class="divContent">
        		<p class="fontDinproMedium">CHCode:</p>
        		<div class="rightContent">
        			<div class="locationGroup listGroupDown listGroup">
		                <a class="btnLeft btnPrimary fontDinpro" data-toggle="dropdown" href="javascript:void(0)" link="">
		                    <?php
		                    	if(empty($cur_chcode)) echo "空";
		                    	else
		                          echo $chcode_names[$cur_chcode];
		                    ?>
		                </a>
		                <a class="btnRight btnPrimary" data-toggle="dropdown" href="javascript:void(0)"><span class="caretBottom"></span></a>
		                <ul class="dropDownList fontDinpro">
		                    <?php foreach($chcode_list  as $k): ?>
		                        <li>
		                            <a href="javascript:void(0)" class="fontDinpro" link="<?php echo backend_url($language.'/app/new_chcode/'.$app['app_id'].'/'.$cur_os.'/'.$k); ?>">
		                                <?php echo $chcode_names[$k]; ?>
		                            </a>
		                        </li>
		                    <?php endforeach; ?>
		                </ul>
		            </div>
        		</div>
        	</div>
        	<div class="divContent">
        		<p class="fontDinproMedium">OS:</p>
        		<div class="rightContent">
		            <div class="locationGroup listGroupDown listGroup">
		                <a class="btnLeft btnPrimary fontDinpro" data-toggle="dropdown" href="javascript:void(0)" link="">
		                    <?php
		                    	echo $os[$cur_os];
		                    ?>
		                </a>
		                <a class="btnRight btnPrimary" data-toggle="dropdown" href="javascript:void(0)"><span class="caretBottom"></span></a>
		                <ul class="dropDownList fontDinpro">
		                    <?php foreach($os as $k=>$r): ?>
		                        <li>
		                            <a href="javascript:void(0)" class="fontDinpro" link="<?php echo backend_url($language.'/app/new_chcode/'.$app['app_id'].'/'.$k); ?>">
		                                <?php echo $r; ?>
		                            </a>
		                        </li>
		                    <?php endforeach; ?>
		                </ul>
		            </div>
        		</div>
        	</div>
    	</div>
        <div class="bodyDiv fontDinpro">
            <div class="divContent">
                <p class="fontDinproMedium">AppID:</p>
                <div class="rightContent">
                    <label class="fontDinpro"><?php echo $app['app_id'];?></label>
                </div>
            </div>
        </div>
        <div class="bodyDiv fontDinpro">
            <div class="divContent">
                <p class="fontDinproMedium">Name:</p>
                <div class="rightContent">
                    <label class="fontDinpro"><?php echo $app['name'];?></label>
                </div>
            </div>
        </div>
        <div class="bodyDiv fontDinpro">
            <div class="divContent">
                <p class="fontDinproMedium">Group:</p>
                <div class="rightContent">
                    <label class="fontDinpro"><?php echo $chcode_group_names[$group_id];?></label>
                </div>
            </div>
        </div>

        <?php foreach($params_temp as $k => $v): ?>
        <div class="bodyDiv fontDinpro">
            <div class="divContent">
        		<p class="fontDinproMedium"><?php echo $k;?>:</p>
        		<div class="rightContent">
	        		<label class="waring fontDinpro autoWidth">sample:<?php echo $v;?></label><br />
					<input type="text" name="params_<?php echo $k;?>" value="<?php if(isset($params[$k])){echo $params[$k];}?>" />
    			</div>
        	</div>
        </div>

        <?php endforeach;?>
        <?php if($icon_flag == 1):?>
        <div class="bodyDiv fontDinpro">
            <div class="divContent">
                <p class="fontDinproMedium">Chcode Icon:</p>
                <div class="rightContent">
                    <input type="file" id="pic_p" name="pic_p"/>
                    <button class="fontDinpro" type="button" onclick="pic_p.click();">Picture File</button>
                    <label class="fontDinpro" id="picName_p" name="picName_p">未选择文件</label>
                </div>
                <label class="waring fontDinpro noFloat snapRight">* 宽*高=512*512.</label>
            </div>
            <div class="divContent">
	            <div class="rightContent">
	                <img id='icon' style="width: 200px;" alt='no icon'  src="<?php echo $icon_url;?>">
	                <?php if(form_error('pic_p')!="") { ?>
	                    <label class="waring fontDinpro noFloat snapRight autoWidth"><?php echo form_error('pic_p'); ?></label>
	                <?php } ?>
	            </div>
            </div>
        </div>
        <?php endif;?>
        <button class="btn submitBtn fontDinproBold" href="javascript:void(0)" type='submit'>SUMBIT</button>
        <button class="btn submitBtn fontDinproBold" href="javascript:void(0)" type='button' onclick="location='<?php echo backend_url($language.'/app/chcode_list/'.$app['app_id'].'/'.$cur_os); ?>'">BACK</button>
       <?php echo form_close(); ?>
    </div>
</div>

<script language="JavaScript">
    function handleFileSelect(evt) {
        var files = evt.target.files; // FileList object

        // Loop through the FileList and render image files as thumbnails.
        for (var i = 0, f; f = files[i]; i++) {

            // Only process image files.
            if (!f.type.match('image.*')) {
                continue;
            }

            var reader = new FileReader();

            // Closure to capture the file information.
            reader.onload = (function(theFile) {
                return function(e) {
                    // Render thumbnail.
                    var thumb;
                    thumb = document.getElementById('icon');
                    picName_p.innerHTML  = escape(theFile.name);

                    thumb.src = e.target.result;
                    thumb.title = escape(theFile.name);
                };
            })(f);

            // Read in the image file as a data URL.
            reader.readAsDataURL(f);
        }
    }
    document.getElementById('pic_p').addEventListener('change', handleFileSelect, false);

</script>